Hệ thống xếp lịch học tín chỉ cho sinh viên CNTT trên PHP & MySQL
111.071 lượt xem;
- setup.php
- project /
1 <?php
2 /* initial preps and includes */
3 define('APPGINI_SETUP', true); /* needed in included files to tell that this is the setup script */
4 error_reporting(E_ERROR | E_WARNING | E_PARSE);
5 if(function_exists('set_magic_quotes_runtime')) @set_magic_quotes_runtime(0);
6 $curr_dir = dirname(__FILE__);
7 include("$curr_dir/settings-manager.php");
8 include("$curr_dir/defaultLang.php");
9 include("$curr_dir/language.php");
10 include("$curr_dir/db.php");
11
12 /*
13 Determine execution scenario ...
14 this script is called in 1 of 5 scenarios:
15 1. to display the setup instructions no $_GET['show-form']
16 2. to display the setup form $_GET['show-form'], no $_POST['test'], no $_POST['submit']
17 3. to test the db info, $_POST['test'] no $_POST['submit']
18 4. to save setup data, $_POST['submit']
19 5. to show final success message, $_GET['finish']
20 below here, we determine which scenario is being called
21 */
22 $submit = $test = $form = $finish = false;
23 (isset($_POST['submit']) ? $submit = true :
24 (isset($_POST['test']) ? $test = true :
25 (isset($_GET['show-form']) ? $form = true :
26 (isset($_GET['finish']) ? $finish = true :
27 false))));
28
29
30 /* some function definitions */
31 function undo_magic_quotes($str){
32 return (get_magic_quotes_gpc() ? stripslashes($str) : $str);
33 }
34
35 function isEmail($email){
36 if(preg_match('/^([*+!.&#$¦\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,45})$/i', $email)){
37 return $email;
38 }else{
39 return FALSE;
40 }
41 }
42
43 function setup_allowed_username($username){
44 $username = trim(strtolower($username));
45 if(!preg_match('/^[a-z0-9][a-z0-9 _.@]{3,19}$/', $username) || preg_match('/(@@| |\.\.|___)/', $username)) return false;
46 return $username;
47 }
48
49
50 /* if config file already exists, no need to continue */
51 if(!$finish && detect_config(false)){
52 @header('Location: index.php');
53 exit;
54 }
55
56
57
58 /* include page header, unless we're testing db connection (ajax) */
59 if(session_id()){ @session_write_close(); }
60 @session_name('Jisort');
61 @session_start();
62 $_REQUEST['Embedded'] = 1; /* to prevent displaying the navigation bar */
63 $x = new StdClass;
64 $x->TableTitle = $Translation['Setup Data']; /* page title */
65 if(!$test) include_once("$curr_dir/header.php");
66
67 if($submit || $test){
68
69 /* receive posted data */
70 if($submit){
71 $username = setup_allowed_username($_POST['username']);
72 $email = isEmail($_POST['email']);
73 $password = $_POST['password'];
74 $confirmPassword = $_POST['confirmPassword'];
75 }
76 $db_name = str_replace('`', '', $_POST['db_name']);
77 $db_password = $_POST['db_password'];
78 $db_server = $_POST['db_server'];
79 $db_username = $_POST['db_username'];
80
81 /* validate data */
82 $errors = array();
83 if($submit){
84 if(!$username){
85 $errors[] = $Translation['username invalid'];
86 }
87 if(strlen($password) < 4 || trim($password) != $password){
88 $errors[] = $Translation['password invalid'];
89 }
90 if($password != $confirmPassword){
91 $errors[] = $Translation['password no match'];
92 }
93 if(!$email){
94 $errors[] = $Translation['email invalid'];
95 }
96 }
97
98 /* test database connection */
99 if(!($connection = @db_connect($db_server, $db_username, $db_password))){
100 $errors[] = $Translation['Database connection error'];
101 }
102 if($connection !== false && !@db_select_db($db_name, $connection)){
103 // attempt to create the database
104 if(!@db_query("CREATE DATABASE IF NOT EXISTS `$db_name`")){
105 $errors[] = @db_error($connection);
106 }elseif(!@db_select_db($db_name, $connection)){
107 $errors[] = @db_error($connection);
108 }
109 }
110
111 /* in case of validation errors, output them and exit */
112 if(count($errors)){
113 if($test){
114 echo 'ERROR!';
115 exit;
116 }
117
118 ?>
119 <div class="row">
120 <div class="col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
121 <h2 class="text-danger"><?php echo $Translation['The following errors occured']; ?></h2>
122 <div class="alert alert-danger"><ul><li><?php echo implode('</li><li>', $errors); ?></li></ul></div>
123 <a class="btn btn-default btn-lg vspacer-lg" href="#" onclick="history.go(-1); return false;"><i class="glyphicon glyphicon-chevron-left"></i> <?php echo $Translation['< back']; ?></a>
124 </div>
125 </div>
126 <?php
127 include_once("$curr_dir/footer.php");
128 exit;
129 }
130
131 /* if db test is successful, output success message and exit */
132 if($test){
133 echo 'SUCCESS!';
134 exit;
135 }
136
137 /* create database tables */
138 $silent = false;
139 include("$curr_dir/updateDB.php");
140
141
142 /* attempt to save db config file */
143 $new_config = array(
144 'dbServer' => undo_magic_quotes($db_server),
145 'dbUsername' => undo_magic_quotes($db_username),
146 'dbPassword' => undo_magic_quotes($db_password),
147 'dbDatabase' => undo_magic_quotes($db_name),
148
149 'adminConfig' => array(
150 'adminUsername' => $username,
151 'adminPassword' => md5($password),
152 'notifyAdminNewMembers' => false,
153 'defaultSignUp' => 1,
154 'anonymousGroup' => 'anonymous',
155 'anonymousMember' => 'guest',
156 'groupsPerPage' => 10,
157 'membersPerPage' => 10,
158 'recordsPerPage' => 10,
159 'custom1' => 'Full Name',
160 'custom2' => 'Address',
161 'custom3' => 'City',
162 'custom4' => 'State',
163 'MySQLDateFormat' => '%m/%d/%Y',
164 'PHPDateFormat' => 'n/j/Y',
165 'PHPDateTimeFormat' => 'm/d/Y, h:i a',
166 'senderName' => 'Membership management',
167 'senderEmail' => $email,
168 'approvalSubject' => 'Your membership is now approved',
169 'approvalMessage' => "Dear member,\n\nYour membership is now approved by the admin. You can log in to your account here:\nhttp://{$_SERVER['HTTP_HOST']}" . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "\n\nRegards,\nAdmin",
170 'hide_twitter_feed' => false,
171 'maintenance_mode_message' => '<b>Our website is currently down for maintenance</b><br>\r\nWe expect to be back in a couple hours. Thanks for your patience.',
172 'mail_function' => 'mail',
173 'smtp_server' => '',
174 'smtp_encryption' => '',
175 'smtp_port' => 25,
176 'smtp_user' => '',
177 'smtp_pass' => ''
178 )
179 );
180
181 $save_result = save_config($new_config);
182 if($save_result !== true){
183 // display instructions for manually creating them if saving not successful
184 $folder_path_formatted = '<strong>' . dirname(__FILE__) . '</strong>';
185 ?>
186 <div class="row">
187 <div class="col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
188 <p style="background-color: white; padding: 20px; margin-bottom: 40px; border-radius: 4px;"><img src="logo.png"></p>
189 <div class="alert alert-danger"><?php echo $Translation['error:'] . ' ' . $save_result['error']; ?></div>
190 <?php printf($Translation['failed to create config instructions'], $folder_path_formatted); ?>
191 <pre style="overflow: scroll; font-size: large;"><?php echo htmlspecialchars($save_result['config']); ?></pre>
192 </div>
193 </div>
194 <?php
195 exit;
196 }
197
198
199 /* sign in as admin if everything went ok */
200 $_SESSION['adminUsername'] = $username;
201 $_SESSION['memberID'] = $username;
202 $_SESSION['memberGroupID'] = 2; // this should work fine in most cases
203
204
205
206 /* redirect to finish page using javascript */
207 ?>
208 <script>
209 jQuery(function(){
210 var a = window.location.href + '?finish=1';
211
212 if(jQuery('div[class="text-danger"]').length){
213 jQuery('body').append('<p class="text-center"><a href="' + a + '" class="btn btn-default vspacer-lg"><?php echo addslashes($Translation['Continue']); ?> <i class="glyphicon glyphicon-chevron-right"></i></a></p>');
214 }else{
215 jQuery('body').append('<div id="manual-redir" style="width: 400px; margin: 10px auto;">If not redirected automatically, <a href="<?php echo basename(__FILE__); ?>?finish=1">click here</a>!</div>');
216 window.location = a;
217 }
218 });
219 </script>
220 <?php
221
222 // exit
223 include_once("$curr_dir/footer.php");
224 exit;
225 }elseif($finish){
226 detect_config();
227 @include("$curr_dir/config.php");
228 }
229 ?>
230
231 <div class="row"><div class="col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
232 <?php
233 if(!$form && !$finish){ /* show checks and instructions */
234
235 /* initial checks */
236 $checks = array(); /* populate with array('class' => 'warning|danger', 'message' => 'error message') */
237
238 if(!extension_loaded('mysql') && !extension_loaded('mysqli')){
239 $checks[] = array(
240 'class' => 'danger',
241 'message' => 'ERROR: PHP is not configured to connect to MySQL on this machine. Please see <a href=http://www.php.net/manual/en/ref.mysql.php>this page</a> for help on how to configure MySQL.'
242 );
243 }
244
245 if(!extension_loaded('iconv')){
246 $checks[] = array(
247 'class' => 'warning',
248 'message' => 'WARNING: PHP is not configured to use iconv on this machine. Some features of this application might not function correctly. Please see <a href=http://php.net/manual/en/book.iconv.php>this page</a> for help on how to configure iconv.'
249 );
250 ?>
251 <div class="alert alert-warning alert-dismissable">
252 <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
253
254 </div>
255 <?php
256 }
257
258 if(!extension_loaded('gd')){
259 $checks[] = array(
260 'class' => 'warning',
261 'message' => 'WARNING: PHP is not configured to use GD on this machine. This will prevent creating thumbnails of uploaded images. Please see <a href=http://php.net/manual/en/book.image.php>this page</a> for help on how to configure GD.'
262 );
263 }
264
265 if(!@is_writable("{$curr_dir}/images")){
266 $checks[] = array(
267 'class' => 'warning',
268 'message' => '<div style="text-direction: ltr; text-align: left;">WARNING: <dfn><abbr title="' . dirname(__FILE__) . '/images">images</abbr></dfn> folder is not writeable. This will prevent file uploads from working correctly. Please set that folder as writeable.<br><br>For example, you might need to <code>chmod 777</code> using FTP, or if this is a linux system and you have shell access, better try using <code>chown -R www-data:www-data ' . dirname(__FILE__) . '</code>, replacing <i>www-data</i> with the actual username running the server process if necessary.</div>'
269 );
270 }
271
272 if(count($checks) && !isset($_POST['test'])){
273 $stop_setup = false;
274 ?>
275 <div class="panel panel-warning vspacer-lg">
276 <div class="panel-heading"><h3 class="panel-title">Warnings</h3></div>
277 <div class="panel-body">
278 <?php foreach($checks as $chk){ if($chk['class'] == 'danger'){ $stop_setup = true; } ?>
279 <div class="text-<?php echo $chk['class']; ?> vspacer-lg">
280 <i class="glyphicon glyphicon-<?php echo ($chk['class'] == 'danger' ? 'remove' : 'exclamation-sign'); ?>"></i>
281 <?php echo $chk['message']; ?>
282 </div>
283 <?php } ?>
284 <a href="setup.php" class="btn btn-success pull-right vspacer-lg hspacer-lg"><i class="glyphicon glyphicon-refresh"></i> Recheck</a>
285 </div>
286 <?php if($stop_setup){ ?>
287 <div class="panel-footer">You must fix at least the issues marked with <i class="glyphicon glyphicon-remove text-danger"></i> before continuing ...</div>
288 <?php } ?>
289 </div>
290 <?php
291 if($stop_setup) exit;
292 }
293 ?>
294
295 <div id="intro1" class="instructions">
296 <p style="background-color: white; padding: 20px; margin-bottom: 40px; border-radius: 4px;"><img src="logo.png"></p>
297 <p><?php echo $Translation['setup intro 1']; ?></p>
298 <br><br>
299 <p class="text-center"><button class="btn btn-default" id="show-intro2" type="button"><?php echo $Translation['Continue']; ?> <i class="glyphicon glyphicon-chevron-right"></i></button></p>
300 </div>
301
302 <div id="intro2" class="instructions" style="display: none;">
303 <p style="background-color: white; padding: 20px; margin-bottom: 40px; border-radius: 4px;"><img src="logo.png"></p>
304 <p><?php echo $Translation['setup intro 2']; ?></p>
305 <br><br>
306 <p class="text-center"><button class="btn btn-success btn-lg" id="show-login-form" type="button"><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['Lets go']; ?></button></p>
307 </div>
308
309 <?php }elseif($form){ /* show setup form */ ?>
310
311 <div class="page-header"><h1><?php echo $Translation['Setup Data']; ?></h1></div>
312
313 <form method="post" action="<?php echo basename(__FILE__); ?>" onSubmit="return jsValidateSetup();" id="login-form" style="display: none;">
314 <fieldset id="database" class="form-horizontal">
315 <legend><?php echo $Translation['Database Information']; ?></legend>
316
317 <div class="form-group">
318 <label for="db_server" class="control-label col-sm-4"><?php echo $Translation['mysql server']; ?></label>
319 <div class="col-sm-8">
320 <div class="input-group">
321 <input type="text" class="form-control" id="db_server" name="db_server" placeholder="<?php echo htmlspecialchars($Translation['mysql server']); ?>" value="localhost">
322 <span class="input-group-btn">
323 <button data-toggle="collapse" tabindex="-1" data-target="#db_server-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
324 </span>
325 </div>
326 <span class="help-block collapse" id="db_server-help"><?php echo $Translation['db_server help']; ?></span>
327 </div>
328 </div>
329
330 <div class="form-group">
331 <label for="db_name" class="control-label col-sm-4"><?php echo $Translation['mysql db']; ?></label>
332 <div class="col-sm-8">
333 <div class="input-group">
334 <input type="text" class="form-control" id="db_name" name="db_name" placeholder="<?php echo htmlspecialchars($Translation['mysql db']); ?>">
335 <span class="input-group-btn">
336 <button data-toggle="collapse" tabindex="-1" data-target="#db_name-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
337 </span>
338 </div>
339 <span class="help-block collapse" id="db_name-help"><?php echo $Translation['db_name help']; ?></span>
340 </div>
341 </div>
342
343 <div class="form-group">
344 <label for="db_username" class="control-label col-sm-4"><?php echo $Translation['mysql username']; ?></label>
345 <div class="col-sm-8">
346 <div class="input-group">
347 <input type="text" class="form-control" id="db_username" name="db_username" placeholder="<?php echo htmlspecialchars($Translation['mysql username']); ?>">
348 <span class="input-group-btn">
349 <button data-toggle="collapse" tabindex="-1" data-target="#db_username-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
350 </span>
351 </div>
352 <span class="help-block collapse" id="db_username-help"><?php echo $Translation['db_username help']; ?></span>
353 </div>
354 </div>
355
356 <div class="form-group">
357 <label for="db_password" class="control-label col-sm-4"><?php echo $Translation['mysql password']; ?></label>
358 <div class="col-sm-8">
359 <div class="input-group">
360 <input type="password" class="form-control" id="db_password" name="db_password" placeholder="<?php echo htmlspecialchars($Translation['mysql password']); ?>">
361 <span class="input-group-btn">
362 <button data-toggle="collapse" tabindex="-1" data-target="#db_password-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
363 </span>
364 </div>
365 <span class="help-block collapse" id="db_password-help"><?php echo $Translation['db_password help']; ?></span>
366 </div>
367 </div>
368
369 <div id="db_test" class="alert" style="display: none;"></div>
370 </fieldset>
371
372 <fieldset class="form-horizontal" id="inputs">
373 <legend><?php echo $Translation['Admin Information']; ?></legend>
374
375 <div class="row form-group">
376 <label for="username" class="control-label col-sm-4"><?php echo $Translation['username']; ?></label>
377 <div class="col-sm-8">
378 <div class="input-group">
379 <input type="text" required class="form-control" id="username" name="username" placeholder="<?php echo htmlspecialchars($Translation['username']); ?>">
380 <span class="input-group-btn">
381 <button data-toggle="collapse" tabindex="-1" data-target="#username-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
382 </span>
383 </div>
384 <span class="help-block collapse" id="username-help"><?php echo $Translation['username help']; ?></span>
385 </div>
386 </div>
387
388 <div class="form-group">
389 <label for="email" class="control-label col-sm-4"><?php echo $Translation['email']; ?></label>
390 <div class="col-sm-8">
391 <div class="input-group">
392 <input type="text" required class="form-control" id="email" name="email" placeholder="<?php echo htmlspecialchars($Translation['email']); ?>">
393 <span class="input-group-btn">
394 <button data-toggle="collapse" tabindex="-1" data-target="#email-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
395 </span>
396 </div>
397 <span class="help-block collapse" id="email-help"><?php echo $Translation['email help']; ?></span>
398 </div>
399 </div>
400 </fieldset>
401
402 <div class="row">
403 <div class="col-sm-6">
404 <div class="form-group">
405 <label for="password" class="control-label"><?php echo $Translation['password']; ?></label>
406 <div class="input-group">
407 <input type="password" required class="form-control" id="password" name="password" placeholder="<?php echo htmlspecialchars($Translation['password']); ?>">
408 <span class="input-group-btn">
409 <button data-toggle="collapse" tabindex="-1" data-target="#password-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
410 </span>
411 </div>
412 <span class="help-block collapse" id="password-help"><?php echo $Translation['password help']; ?></span>
413 </div>
414 </div>
415 <div class="col-sm-6">
416 <div class="form-group">
417 <label for="confirmPassword" class="control-label"><?php echo $Translation['confirm password']; ?></label>
418 <input type="password" required class="form-control" id="confirmPassword" name="confirmPassword" placeholder="<?php echo htmlspecialchars($Translation['confirm password']); ?>">
419 </div>
420 </div>
421 </div>
422
423 <div class="row">
424 <div class="col-sm-offset-3 col-sm-6">
425 <button class="btn btn-primary btn-lg btn-block" value="submit" id="submit" type="submit" name="submit"><?php echo $Translation['Submit']; ?></button>
426 </div>
427 </div>
428 </form>
429
430 <?php }elseif($finish){ ?>
431
432 <?php
433 // make sure this is an admin
434 if(!$_SESSION['adminUsername']){
435 ?>
436 <div id="manual-redir" style="width: 400px; margin: 10px auto;">If not redirected automatically, <a href="index.php">click here</a>!</div>
437 <script>
438 window.location = 'index.php';
439 </script>
440 <?php
441 exit;
442 }
443 ?>
444
445 <div class="instructions">
446 <p style="background-color: white; padding: 20px; margin-bottom: 40px; border-radius: 4px;"><img src="logo.png"></p>
447 <div class="panel panel-success">
448 <div class="panel-heading">
449 <h3 class="panel-title"><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['setup finished']; ?></h3>
450 </div>
451 <div class="panel-content">
452 <ul id="next-actions" class="nav nav-pills nav-stacked">
453 <li class="acive"><a href="index.php"><i class="glyphicon glyphicon-play"></i> <b><?php echo $Translation['setup next 1']; ?></b></a></li>
454 <li><a href="admin/pageUploadCSV.php"><i class="glyphicon glyphicon-upload"></i> <?php echo $Translation['setup next 2']; ?></a></li>
455 <li><a href="admin/pageHome.php"><i class="glyphicon glyphicon-cog"></i> <?php echo $Translation['setup next 3']; ?></a></li>
456 </ul>
457 </div>
458 </div>
459 </div>
460
461 <?php } ?>
462 </div></div>
463
464 <script>
465 <?php if(!$form && !$finish){ ?>
466 $j(function() {
467 $('show-intro2').observe('click', function(){
468 $('intro1').hide();
469 $('intro2').appear({ duration: 2 });
470 });
471 $('show-login-form').observe('click', function(){
472 var a = window.location.href;
473 window.location = a + '?show-form=1';
474 });
475 });
476 <?php }elseif($form){ ?>
477 $j(function() {
478 /* password strength feedback */
479 $('password').observe('keyup', function(){
480 ps = passwordStrength($F('password'), $F('username'));
481
482 if(ps == 'strong'){
483 $j('#password').parents('.form-group').removeClass('has-error has-warning').addClass('has-success');
484 $('password').title = '<?php echo htmlspecialchars($Translation['Password strength: strong']); ?>';
485 }else if(ps == 'good'){
486 $j('#password').parents('.form-group').removeClass('has-error has-success').addClass('has-warning');
487 $('password').title = '<?php echo htmlspecialchars($Translation['Password strength: good']); ?>';
488 }else{
489 $j('#password').parents('.form-group').removeClass('has-success has-warning').addClass('has-error');
490 $('password').title = '<?php echo htmlspecialchars($Translation['Password strength: weak']); ?>';
491 }
492 });
493
494 /* inline feedback of confirm password */
495 $('confirmPassword').observe('keyup', function(){
496 if($F('confirmPassword') != $F('password') || !$F('confirmPassword').length){
497 $j('#confirmPassword').parents('.form-group').removeClass('has-success').addClass('has-error');
498 }else{
499 $j('#confirmPassword').parents('.form-group').removeClass('has-error').addClass('has-success');
500 }
501 });
502
503 /* inline feedback of email */
504 $('email').observe('change', function(){
505 if(validateEmail($F('email'))){
506 $j('#email').parents('.form-group').removeClass('has-error').addClass('has-success');
507 }else{
508 $j('#email').parents('.form-group').removeClass('has-success').addClass('has-error');
509 }
510 });
511
512 $('login-form').appear({ duration: 2 });
513 setTimeout("$('db_name').focus();", 2006);
514
515 $('db_name').observe('change', function(){ /* */ db_test(); });
516 $('db_password').observe('change', function(){ /* */ db_test(); });
517 $('db_server').observe('change', function(){ /* */ db_test(); });
518 $('db_username').observe('change', function(){ /* */ db_test(); });
519 });
520
521 /* validate data before submitting */
522 function jsValidateSetup(){
523 var p1 = $F('password');
524 var p2 = $F('confirmPassword');
525 var user = $F('username');
526 var email = $F('email');
527
528 /* passwords not matching? */
529 if(p1 != p2){
530 modal_window({ message: '<div class="alert alert-danger"><?php echo addslashes($Translation['password no match']); ?></div>', title: "<?php echo addslashes($Translation['error:']); ?>", close: function(){ /* */ jQuery('#confirmPassword').focus(); } });
531 return false;
532 }
533
534 /* user exists? */
535 if($('usernameNotAvailable').visible()){
536 modal_window({ message: '<div class="alert alert-danger"><?php echo addslashes($Translation['username invalid']); ?></div>', title: "<?php echo addslashes($Translation['error:']); ?>", close: function(){ /* */ jQuery('#username').focus(); } });
537 return false;
538 }
539
540 return true;
541 }
542
543 /* test db info */
544 var db_test_in_progress = false;
545 function db_test(){
546 if(db_test_in_progress) return;
547
548 if($F('db_name').length && $F('db_username').length && $F('db_server').length && $$('#db_password:focus') == ''){
549 setTimeout(function(){
550 if(db_test_in_progress) return;
551
552 new Ajax.Request(
553 '<?php echo basename(__FILE__); ?>', {
554 method: 'post',
555 parameters: {
556 db_name: $F('db_name'),
557 db_server: $F('db_server'),
558 db_password: $F('db_password'),
559 db_username: $F('db_username'),
560 test: 1
561 },
562 onCreate: function() {
563 db_test_in_progress = true;
564 },
565 onSuccess: function(resp) {
566 if(resp.responseText == 'SUCCESS!'){
567 $('db_test').removeClassName('alert-danger').addClassName('alert-success').update('<?php echo addslashes($Translation['Database info is correct']); ?>').appear();
568 }else if(resp.responseText.match(/^ERROR!/)){
569 $('db_test').removeClassName('alert-success').addClassName('alert-danger').update('<?php echo addslashes($Translation['Database connection error']); ?>').show();
570 Effect.Shake('db_test');
571 }
572 },
573 onComplete: function() {
574 db_test_in_progress = false;
575 }
576 }
577 );
578 }, 1000);
579 }
580 }
581 <?php } ?>
582 </script>
583
584 <style>
585 legend{ font-weight: bold; }
586 #usernameAvailable,#usernameNotAvailable{ cursor: pointer; }
587
588 .instructions{
589 padding: 30px;
590 margin: 40px auto;
591 border: solid 1px silver;
592 border-radius: 4px;
593 }
594 .instructions img{ display: block; margin: auto; }
595 .instructions .buttons{
596 display: block;
597 height: 1px;
598 margin: 30px auto;
599 }
600 ul#next-actions li { font-size: 1.3em; }
601 ul#next-actions { padding: 2em; }
602 </style>
603
604 <?php include_once("$curr_dir/footer.php"); ?>
2 /* initial preps and includes */
3 define('APPGINI_SETUP', true); /* needed in included files to tell that this is the setup script */
4 error_reporting(E_ERROR | E_WARNING | E_PARSE);
5 if(function_exists('set_magic_quotes_runtime')) @set_magic_quotes_runtime(0);
6 $curr_dir = dirname(__FILE__);
7 include("$curr_dir/settings-manager.php");
8 include("$curr_dir/defaultLang.php");
9 include("$curr_dir/language.php");
10 include("$curr_dir/db.php");
11
12 /*
13 Determine execution scenario ...
14 this script is called in 1 of 5 scenarios:
15 1. to display the setup instructions no $_GET['show-form']
16 2. to display the setup form $_GET['show-form'], no $_POST['test'], no $_POST['submit']
17 3. to test the db info, $_POST['test'] no $_POST['submit']
18 4. to save setup data, $_POST['submit']
19 5. to show final success message, $_GET['finish']
20 below here, we determine which scenario is being called
21 */
22 $submit = $test = $form = $finish = false;
23 (isset($_POST['submit']) ? $submit = true :
24 (isset($_POST['test']) ? $test = true :
25 (isset($_GET['show-form']) ? $form = true :
26 (isset($_GET['finish']) ? $finish = true :
27 false))));
28
29
30 /* some function definitions */
31 function undo_magic_quotes($str){
32 return (get_magic_quotes_gpc() ? stripslashes($str) : $str);
33 }
34
35 function isEmail($email){
36 if(preg_match('/^([*+!.&#$¦\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,45})$/i', $email)){
37 return $email;
38 }else{
39 return FALSE;
40 }
41 }
42
43 function setup_allowed_username($username){
44 $username = trim(strtolower($username));
45 if(!preg_match('/^[a-z0-9][a-z0-9 _.@]{3,19}$/', $username) || preg_match('/(@@| |\.\.|___)/', $username)) return false;
46 return $username;
47 }
48
49
50 /* if config file already exists, no need to continue */
51 if(!$finish && detect_config(false)){
52 @header('Location: index.php');
53 exit;
54 }
55
56
57
58 /* include page header, unless we're testing db connection (ajax) */
59 if(session_id()){ @session_write_close(); }
60 @session_name('Jisort');
61 @session_start();
62 $_REQUEST['Embedded'] = 1; /* to prevent displaying the navigation bar */
63 $x = new StdClass;
64 $x->TableTitle = $Translation['Setup Data']; /* page title */
65 if(!$test) include_once("$curr_dir/header.php");
66
67 if($submit || $test){
68
69 /* receive posted data */
70 if($submit){
71 $username = setup_allowed_username($_POST['username']);
72 $email = isEmail($_POST['email']);
73 $password = $_POST['password'];
74 $confirmPassword = $_POST['confirmPassword'];
75 }
76 $db_name = str_replace('`', '', $_POST['db_name']);
77 $db_password = $_POST['db_password'];
78 $db_server = $_POST['db_server'];
79 $db_username = $_POST['db_username'];
80
81 /* validate data */
82 $errors = array();
83 if($submit){
84 if(!$username){
85 $errors[] = $Translation['username invalid'];
86 }
87 if(strlen($password) < 4 || trim($password) != $password){
88 $errors[] = $Translation['password invalid'];
89 }
90 if($password != $confirmPassword){
91 $errors[] = $Translation['password no match'];
92 }
93 if(!$email){
94 $errors[] = $Translation['email invalid'];
95 }
96 }
97
98 /* test database connection */
99 if(!($connection = @db_connect($db_server, $db_username, $db_password))){
100 $errors[] = $Translation['Database connection error'];
101 }
102 if($connection !== false && !@db_select_db($db_name, $connection)){
103 // attempt to create the database
104 if(!@db_query("CREATE DATABASE IF NOT EXISTS `$db_name`")){
105 $errors[] = @db_error($connection);
106 }elseif(!@db_select_db($db_name, $connection)){
107 $errors[] = @db_error($connection);
108 }
109 }
110
111 /* in case of validation errors, output them and exit */
112 if(count($errors)){
113 if($test){
114 echo 'ERROR!';
115 exit;
116 }
117
118 ?>
119 <div class="row">
120 <div class="col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
121 <h2 class="text-danger"><?php echo $Translation['The following errors occured']; ?></h2>
122 <div class="alert alert-danger"><ul><li><?php echo implode('</li><li>', $errors); ?></li></ul></div>
123 <a class="btn btn-default btn-lg vspacer-lg" href="#" onclick="history.go(-1); return false;"><i class="glyphicon glyphicon-chevron-left"></i> <?php echo $Translation['< back']; ?></a>
124 </div>
125 </div>
126 <?php
127 include_once("$curr_dir/footer.php");
128 exit;
129 }
130
131 /* if db test is successful, output success message and exit */
132 if($test){
133 echo 'SUCCESS!';
134 exit;
135 }
136
137 /* create database tables */
138 $silent = false;
139 include("$curr_dir/updateDB.php");
140
141
142 /* attempt to save db config file */
143 $new_config = array(
144 'dbServer' => undo_magic_quotes($db_server),
145 'dbUsername' => undo_magic_quotes($db_username),
146 'dbPassword' => undo_magic_quotes($db_password),
147 'dbDatabase' => undo_magic_quotes($db_name),
148
149 'adminConfig' => array(
150 'adminUsername' => $username,
151 'adminPassword' => md5($password),
152 'notifyAdminNewMembers' => false,
153 'defaultSignUp' => 1,
154 'anonymousGroup' => 'anonymous',
155 'anonymousMember' => 'guest',
156 'groupsPerPage' => 10,
157 'membersPerPage' => 10,
158 'recordsPerPage' => 10,
159 'custom1' => 'Full Name',
160 'custom2' => 'Address',
161 'custom3' => 'City',
162 'custom4' => 'State',
163 'MySQLDateFormat' => '%m/%d/%Y',
164 'PHPDateFormat' => 'n/j/Y',
165 'PHPDateTimeFormat' => 'm/d/Y, h:i a',
166 'senderName' => 'Membership management',
167 'senderEmail' => $email,
168 'approvalSubject' => 'Your membership is now approved',
169 'approvalMessage' => "Dear member,\n\nYour membership is now approved by the admin. You can log in to your account here:\nhttp://{$_SERVER['HTTP_HOST']}" . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "\n\nRegards,\nAdmin",
170 'hide_twitter_feed' => false,
171 'maintenance_mode_message' => '<b>Our website is currently down for maintenance</b><br>\r\nWe expect to be back in a couple hours. Thanks for your patience.',
172 'mail_function' => 'mail',
173 'smtp_server' => '',
174 'smtp_encryption' => '',
175 'smtp_port' => 25,
176 'smtp_user' => '',
177 'smtp_pass' => ''
178 )
179 );
180
181 $save_result = save_config($new_config);
182 if($save_result !== true){
183 // display instructions for manually creating them if saving not successful
184 $folder_path_formatted = '<strong>' . dirname(__FILE__) . '</strong>';
185 ?>
186 <div class="row">
187 <div class="col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
188 <p style="background-color: white; padding: 20px; margin-bottom: 40px; border-radius: 4px;"><img src="logo.png"></p>
189 <div class="alert alert-danger"><?php echo $Translation['error:'] . ' ' . $save_result['error']; ?></div>
190 <?php printf($Translation['failed to create config instructions'], $folder_path_formatted); ?>
191 <pre style="overflow: scroll; font-size: large;"><?php echo htmlspecialchars($save_result['config']); ?></pre>
192 </div>
193 </div>
194 <?php
195 exit;
196 }
197
198
199 /* sign in as admin if everything went ok */
200 $_SESSION['adminUsername'] = $username;
201 $_SESSION['memberID'] = $username;
202 $_SESSION['memberGroupID'] = 2; // this should work fine in most cases
203
204
205
206 /* redirect to finish page using javascript */
207 ?>
208 <script>
209 jQuery(function(){
210 var a = window.location.href + '?finish=1';
211
212 if(jQuery('div[class="text-danger"]').length){
213 jQuery('body').append('<p class="text-center"><a href="' + a + '" class="btn btn-default vspacer-lg"><?php echo addslashes($Translation['Continue']); ?> <i class="glyphicon glyphicon-chevron-right"></i></a></p>');
214 }else{
215 jQuery('body').append('<div id="manual-redir" style="width: 400px; margin: 10px auto;">If not redirected automatically, <a href="<?php echo basename(__FILE__); ?>?finish=1">click here</a>!</div>');
216 window.location = a;
217 }
218 });
219 </script>
220 <?php
221
222 // exit
223 include_once("$curr_dir/footer.php");
224 exit;
225 }elseif($finish){
226 detect_config();
227 @include("$curr_dir/config.php");
228 }
229 ?>
230
231 <div class="row"><div class="col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
232 <?php
233 if(!$form && !$finish){ /* show checks and instructions */
234
235 /* initial checks */
236 $checks = array(); /* populate with array('class' => 'warning|danger', 'message' => 'error message') */
237
238 if(!extension_loaded('mysql') && !extension_loaded('mysqli')){
239 $checks[] = array(
240 'class' => 'danger',
241 'message' => 'ERROR: PHP is not configured to connect to MySQL on this machine. Please see <a href=http://www.php.net/manual/en/ref.mysql.php>this page</a> for help on how to configure MySQL.'
242 );
243 }
244
245 if(!extension_loaded('iconv')){
246 $checks[] = array(
247 'class' => 'warning',
248 'message' => 'WARNING: PHP is not configured to use iconv on this machine. Some features of this application might not function correctly. Please see <a href=http://php.net/manual/en/book.iconv.php>this page</a> for help on how to configure iconv.'
249 );
250 ?>
251 <div class="alert alert-warning alert-dismissable">
252 <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
253
254 </div>
255 <?php
256 }
257
258 if(!extension_loaded('gd')){
259 $checks[] = array(
260 'class' => 'warning',
261 'message' => 'WARNING: PHP is not configured to use GD on this machine. This will prevent creating thumbnails of uploaded images. Please see <a href=http://php.net/manual/en/book.image.php>this page</a> for help on how to configure GD.'
262 );
263 }
264
265 if(!@is_writable("{$curr_dir}/images")){
266 $checks[] = array(
267 'class' => 'warning',
268 'message' => '<div style="text-direction: ltr; text-align: left;">WARNING: <dfn><abbr title="' . dirname(__FILE__) . '/images">images</abbr></dfn> folder is not writeable. This will prevent file uploads from working correctly. Please set that folder as writeable.<br><br>For example, you might need to <code>chmod 777</code> using FTP, or if this is a linux system and you have shell access, better try using <code>chown -R www-data:www-data ' . dirname(__FILE__) . '</code>, replacing <i>www-data</i> with the actual username running the server process if necessary.</div>'
269 );
270 }
271
272 if(count($checks) && !isset($_POST['test'])){
273 $stop_setup = false;
274 ?>
275 <div class="panel panel-warning vspacer-lg">
276 <div class="panel-heading"><h3 class="panel-title">Warnings</h3></div>
277 <div class="panel-body">
278 <?php foreach($checks as $chk){ if($chk['class'] == 'danger'){ $stop_setup = true; } ?>
279 <div class="text-<?php echo $chk['class']; ?> vspacer-lg">
280 <i class="glyphicon glyphicon-<?php echo ($chk['class'] == 'danger' ? 'remove' : 'exclamation-sign'); ?>"></i>
281 <?php echo $chk['message']; ?>
282 </div>
283 <?php } ?>
284 <a href="setup.php" class="btn btn-success pull-right vspacer-lg hspacer-lg"><i class="glyphicon glyphicon-refresh"></i> Recheck</a>
285 </div>
286 <?php if($stop_setup){ ?>
287 <div class="panel-footer">You must fix at least the issues marked with <i class="glyphicon glyphicon-remove text-danger"></i> before continuing ...</div>
288 <?php } ?>
289 </div>
290 <?php
291 if($stop_setup) exit;
292 }
293 ?>
294
295 <div id="intro1" class="instructions">
296 <p style="background-color: white; padding: 20px; margin-bottom: 40px; border-radius: 4px;"><img src="logo.png"></p>
297 <p><?php echo $Translation['setup intro 1']; ?></p>
298 <br><br>
299 <p class="text-center"><button class="btn btn-default" id="show-intro2" type="button"><?php echo $Translation['Continue']; ?> <i class="glyphicon glyphicon-chevron-right"></i></button></p>
300 </div>
301
302 <div id="intro2" class="instructions" style="display: none;">
303 <p style="background-color: white; padding: 20px; margin-bottom: 40px; border-radius: 4px;"><img src="logo.png"></p>
304 <p><?php echo $Translation['setup intro 2']; ?></p>
305 <br><br>
306 <p class="text-center"><button class="btn btn-success btn-lg" id="show-login-form" type="button"><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['Lets go']; ?></button></p>
307 </div>
308
309 <?php }elseif($form){ /* show setup form */ ?>
310
311 <div class="page-header"><h1><?php echo $Translation['Setup Data']; ?></h1></div>
312
313 <form method="post" action="<?php echo basename(__FILE__); ?>" onSubmit="return jsValidateSetup();" id="login-form" style="display: none;">
314 <fieldset id="database" class="form-horizontal">
315 <legend><?php echo $Translation['Database Information']; ?></legend>
316
317 <div class="form-group">
318 <label for="db_server" class="control-label col-sm-4"><?php echo $Translation['mysql server']; ?></label>
319 <div class="col-sm-8">
320 <div class="input-group">
321 <input type="text" class="form-control" id="db_server" name="db_server" placeholder="<?php echo htmlspecialchars($Translation['mysql server']); ?>" value="localhost">
322 <span class="input-group-btn">
323 <button data-toggle="collapse" tabindex="-1" data-target="#db_server-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
324 </span>
325 </div>
326 <span class="help-block collapse" id="db_server-help"><?php echo $Translation['db_server help']; ?></span>
327 </div>
328 </div>
329
330 <div class="form-group">
331 <label for="db_name" class="control-label col-sm-4"><?php echo $Translation['mysql db']; ?></label>
332 <div class="col-sm-8">
333 <div class="input-group">
334 <input type="text" class="form-control" id="db_name" name="db_name" placeholder="<?php echo htmlspecialchars($Translation['mysql db']); ?>">
335 <span class="input-group-btn">
336 <button data-toggle="collapse" tabindex="-1" data-target="#db_name-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
337 </span>
338 </div>
339 <span class="help-block collapse" id="db_name-help"><?php echo $Translation['db_name help']; ?></span>
340 </div>
341 </div>
342
343 <div class="form-group">
344 <label for="db_username" class="control-label col-sm-4"><?php echo $Translation['mysql username']; ?></label>
345 <div class="col-sm-8">
346 <div class="input-group">
347 <input type="text" class="form-control" id="db_username" name="db_username" placeholder="<?php echo htmlspecialchars($Translation['mysql username']); ?>">
348 <span class="input-group-btn">
349 <button data-toggle="collapse" tabindex="-1" data-target="#db_username-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
350 </span>
351 </div>
352 <span class="help-block collapse" id="db_username-help"><?php echo $Translation['db_username help']; ?></span>
353 </div>
354 </div>
355
356 <div class="form-group">
357 <label for="db_password" class="control-label col-sm-4"><?php echo $Translation['mysql password']; ?></label>
358 <div class="col-sm-8">
359 <div class="input-group">
360 <input type="password" class="form-control" id="db_password" name="db_password" placeholder="<?php echo htmlspecialchars($Translation['mysql password']); ?>">
361 <span class="input-group-btn">
362 <button data-toggle="collapse" tabindex="-1" data-target="#db_password-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
363 </span>
364 </div>
365 <span class="help-block collapse" id="db_password-help"><?php echo $Translation['db_password help']; ?></span>
366 </div>
367 </div>
368
369 <div id="db_test" class="alert" style="display: none;"></div>
370 </fieldset>
371
372 <fieldset class="form-horizontal" id="inputs">
373 <legend><?php echo $Translation['Admin Information']; ?></legend>
374
375 <div class="row form-group">
376 <label for="username" class="control-label col-sm-4"><?php echo $Translation['username']; ?></label>
377 <div class="col-sm-8">
378 <div class="input-group">
379 <input type="text" required class="form-control" id="username" name="username" placeholder="<?php echo htmlspecialchars($Translation['username']); ?>">
380 <span class="input-group-btn">
381 <button data-toggle="collapse" tabindex="-1" data-target="#username-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
382 </span>
383 </div>
384 <span class="help-block collapse" id="username-help"><?php echo $Translation['username help']; ?></span>
385 </div>
386 </div>
387
388 <div class="form-group">
389 <label for="email" class="control-label col-sm-4"><?php echo $Translation['email']; ?></label>
390 <div class="col-sm-8">
391 <div class="input-group">
392 <input type="text" required class="form-control" id="email" name="email" placeholder="<?php echo htmlspecialchars($Translation['email']); ?>">
393 <span class="input-group-btn">
394 <button data-toggle="collapse" tabindex="-1" data-target="#email-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
395 </span>
396 </div>
397 <span class="help-block collapse" id="email-help"><?php echo $Translation['email help']; ?></span>
398 </div>
399 </div>
400 </fieldset>
401
402 <div class="row">
403 <div class="col-sm-6">
404 <div class="form-group">
405 <label for="password" class="control-label"><?php echo $Translation['password']; ?></label>
406 <div class="input-group">
407 <input type="password" required class="form-control" id="password" name="password" placeholder="<?php echo htmlspecialchars($Translation['password']); ?>">
408 <span class="input-group-btn">
409 <button data-toggle="collapse" tabindex="-1" data-target="#password-help" class="btn btn-info" type="button"><i class="glyphicon glyphicon-info-sign"></i></button>
410 </span>
411 </div>
412 <span class="help-block collapse" id="password-help"><?php echo $Translation['password help']; ?></span>
413 </div>
414 </div>
415 <div class="col-sm-6">
416 <div class="form-group">
417 <label for="confirmPassword" class="control-label"><?php echo $Translation['confirm password']; ?></label>
418 <input type="password" required class="form-control" id="confirmPassword" name="confirmPassword" placeholder="<?php echo htmlspecialchars($Translation['confirm password']); ?>">
419 </div>
420 </div>
421 </div>
422
423 <div class="row">
424 <div class="col-sm-offset-3 col-sm-6">
425 <button class="btn btn-primary btn-lg btn-block" value="submit" id="submit" type="submit" name="submit"><?php echo $Translation['Submit']; ?></button>
426 </div>
427 </div>
428 </form>
429
430 <?php }elseif($finish){ ?>
431
432 <?php
433 // make sure this is an admin
434 if(!$_SESSION['adminUsername']){
435 ?>
436 <div id="manual-redir" style="width: 400px; margin: 10px auto;">If not redirected automatically, <a href="index.php">click here</a>!</div>
437 <script>
438 window.location = 'index.php';
439 </script>
440 <?php
441 exit;
442 }
443 ?>
444
445 <div class="instructions">
446 <p style="background-color: white; padding: 20px; margin-bottom: 40px; border-radius: 4px;"><img src="logo.png"></p>
447 <div class="panel panel-success">
448 <div class="panel-heading">
449 <h3 class="panel-title"><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['setup finished']; ?></h3>
450 </div>
451 <div class="panel-content">
452 <ul id="next-actions" class="nav nav-pills nav-stacked">
453 <li class="acive"><a href="index.php"><i class="glyphicon glyphicon-play"></i> <b><?php echo $Translation['setup next 1']; ?></b></a></li>
454 <li><a href="admin/pageUploadCSV.php"><i class="glyphicon glyphicon-upload"></i> <?php echo $Translation['setup next 2']; ?></a></li>
455 <li><a href="admin/pageHome.php"><i class="glyphicon glyphicon-cog"></i> <?php echo $Translation['setup next 3']; ?></a></li>
456 </ul>
457 </div>
458 </div>
459 </div>
460
461 <?php } ?>
462 </div></div>
463
464 <script>
465 <?php if(!$form && !$finish){ ?>
466 $j(function() {
467 $('show-intro2').observe('click', function(){
468 $('intro1').hide();
469 $('intro2').appear({ duration: 2 });
470 });
471 $('show-login-form').observe('click', function(){
472 var a = window.location.href;
473 window.location = a + '?show-form=1';
474 });
475 });
476 <?php }elseif($form){ ?>
477 $j(function() {
478 /* password strength feedback */
479 $('password').observe('keyup', function(){
480 ps = passwordStrength($F('password'), $F('username'));
481
482 if(ps == 'strong'){
483 $j('#password').parents('.form-group').removeClass('has-error has-warning').addClass('has-success');
484 $('password').title = '<?php echo htmlspecialchars($Translation['Password strength: strong']); ?>';
485 }else if(ps == 'good'){
486 $j('#password').parents('.form-group').removeClass('has-error has-success').addClass('has-warning');
487 $('password').title = '<?php echo htmlspecialchars($Translation['Password strength: good']); ?>';
488 }else{
489 $j('#password').parents('.form-group').removeClass('has-success has-warning').addClass('has-error');
490 $('password').title = '<?php echo htmlspecialchars($Translation['Password strength: weak']); ?>';
491 }
492 });
493
494 /* inline feedback of confirm password */
495 $('confirmPassword').observe('keyup', function(){
496 if($F('confirmPassword') != $F('password') || !$F('confirmPassword').length){
497 $j('#confirmPassword').parents('.form-group').removeClass('has-success').addClass('has-error');
498 }else{
499 $j('#confirmPassword').parents('.form-group').removeClass('has-error').addClass('has-success');
500 }
501 });
502
503 /* inline feedback of email */
504 $('email').observe('change', function(){
505 if(validateEmail($F('email'))){
506 $j('#email').parents('.form-group').removeClass('has-error').addClass('has-success');
507 }else{
508 $j('#email').parents('.form-group').removeClass('has-success').addClass('has-error');
509 }
510 });
511
512 $('login-form').appear({ duration: 2 });
513 setTimeout("$('db_name').focus();", 2006);
514
515 $('db_name').observe('change', function(){ /* */ db_test(); });
516 $('db_password').observe('change', function(){ /* */ db_test(); });
517 $('db_server').observe('change', function(){ /* */ db_test(); });
518 $('db_username').observe('change', function(){ /* */ db_test(); });
519 });
520
521 /* validate data before submitting */
522 function jsValidateSetup(){
523 var p1 = $F('password');
524 var p2 = $F('confirmPassword');
525 var user = $F('username');
526 var email = $F('email');
527
528 /* passwords not matching? */
529 if(p1 != p2){
530 modal_window({ message: '<div class="alert alert-danger"><?php echo addslashes($Translation['password no match']); ?></div>', title: "<?php echo addslashes($Translation['error:']); ?>", close: function(){ /* */ jQuery('#confirmPassword').focus(); } });
531 return false;
532 }
533
534 /* user exists? */
535 if($('usernameNotAvailable').visible()){
536 modal_window({ message: '<div class="alert alert-danger"><?php echo addslashes($Translation['username invalid']); ?></div>', title: "<?php echo addslashes($Translation['error:']); ?>", close: function(){ /* */ jQuery('#username').focus(); } });
537 return false;
538 }
539
540 return true;
541 }
542
543 /* test db info */
544 var db_test_in_progress = false;
545 function db_test(){
546 if(db_test_in_progress) return;
547
548 if($F('db_name').length && $F('db_username').length && $F('db_server').length && $$('#db_password:focus') == ''){
549 setTimeout(function(){
550 if(db_test_in_progress) return;
551
552 new Ajax.Request(
553 '<?php echo basename(__FILE__); ?>', {
554 method: 'post',
555 parameters: {
556 db_name: $F('db_name'),
557 db_server: $F('db_server'),
558 db_password: $F('db_password'),
559 db_username: $F('db_username'),
560 test: 1
561 },
562 onCreate: function() {
563 db_test_in_progress = true;
564 },
565 onSuccess: function(resp) {
566 if(resp.responseText == 'SUCCESS!'){
567 $('db_test').removeClassName('alert-danger').addClassName('alert-success').update('<?php echo addslashes($Translation['Database info is correct']); ?>').appear();
568 }else if(resp.responseText.match(/^ERROR!/)){
569 $('db_test').removeClassName('alert-success').addClassName('alert-danger').update('<?php echo addslashes($Translation['Database connection error']); ?>').show();
570 Effect.Shake('db_test');
571 }
572 },
573 onComplete: function() {
574 db_test_in_progress = false;
575 }
576 }
577 );
578 }, 1000);
579 }
580 }
581 <?php } ?>
582 </script>
583
584 <style>
585 legend{ font-weight: bold; }
586 #usernameAvailable,#usernameNotAvailable{ cursor: pointer; }
587
588 .instructions{
589 padding: 30px;
590 margin: 40px auto;
591 border: solid 1px silver;
592 border-radius: 4px;
593 }
594 .instructions img{ display: block; margin: auto; }
595 .instructions .buttons{
596 display: block;
597 height: 1px;
598 margin: 30px auto;
599 }
600 ul#next-actions li { font-size: 1.3em; }
601 ul#next-actions { padding: 2em; }
602 </style>
603
604 <?php include_once("$curr_dir/footer.php"); ?>